package com.hut.oa.model.dao.address;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.hut.oa.model.bean.AddressBook;
import com.hut.oa.model.bean.AddressDir;
import com.hut.oa.model.bean.Apply;
import com.hut.oa.model.bean.DeptOffice;
import com.hut.oa.model.bean.User;

public interface AddressDao extends PagingAndSortingRepository<AddressBook, Long>{
	
	
	
	@Query("from AddressBook ad where  ad.createtime BETWEEN :starttime and :endtime and user=:u")
	Page<AddressBook> selectbytime(Pageable page,@Param("starttime")Date starttime,@Param("endtime")Date endtime,@Param("u")User u);
	
	Page<AddressBook> findByUser(Pageable page,User user);
	
	Page<AddressBook> findByUserAndDir(Pageable page,User user,AddressDir dir);
	
	Page<AddressBook> findByUserAndType(Pageable page,User user,Long type);
	
	Page<AddressBook> findByUserAndTypeAndDir(Pageable page,User user,Long type,AddressDir dir);
	
	AddressBook findById(Long id);
	
	@Query("from AddressBook add where user=:u and(username like CONCAT('%',:value,'%') or tel like CONCAT('%',:value,'%'))")
	Page<AddressBook> findbyUsernameOrtel(Pageable page,@Param("u")User user,@Param("value")String value);
	
	List<AddressBook> findByUserAndDir(User u,AddressDir dir);
	
	@Query("from AddressBook add where add.id in :ids")
	Page<AddressBook> findbyids(Pageable pageable,@Param("ids")List<Long> id);
}
